package channels

import "fmt"

func Close() {
	jobs := make(chan int, 5)
	done := make(chan bool)
	go func() {
		for {
			//more是用来只是jobs是否关闭
			j, more := <-jobs
			if more {
				//fmt.Println("what is it?", more)
				fmt.Println("received job", j)
			} else {
				fmt.Println("received all jobs")
				done <- true
				return
			}
		}
	}()

	for j := 1; j <= 3; j++ {
		jobs <- j
		fmt.Println("sent job", j)
	}

	close(jobs)
	fmt.Println("sent all jobs")

	//通道同步，等待任务结束
	<-done
}
